/*package com.mljr.util;

import java.awt.Font;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.NumberToTextConverter;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.h2.result.Row;

import com.google.common.collect.Table.Cell;

public class PoiUtil {

	public static List<Object[]> readExcel(File file, int sheetIndex, int start) throws IOException {
		return readExcel(new FileInputStream(file), sheetIndex, start);
	}

	public static List<Object[]> readExcel(InputStream in, int sheetIndex, int start) throws IOException {
		List<Object[]> dataList = new ArrayList<Object[]>();

		if (sheetIndex < 0) {
			sheetIndex = 0;
		}

		if (start < 0) {
			start = 0;
		}
		Workbook wb = new XSSFWorkbook(in);
		Sheet sheet = wb.getSheetAt(sheetIndex);
		int rowCount = sheet.getPhysicalNumberOfRows();
		Row row = null;
		Row titleRow = sheet.getRow(0);
		int maxColumn = titleRow.getPhysicalNumberOfCells();
		for (int i = start; i < rowCount; i++) {
			row = sheet.getRow(i);
			Object[] data = new String[maxColumn];
			for (int j = 0; j < maxColumn; j++) {
				Cell cell = row.getCell(j);
				if (cell != null) {
					data[j] = getCellInfo(cell);
				} else {
					data[j] = "";
				}
			}
			dataList.add(data);
		}
		wb.close();
		return dataList;
	}

	public static File writeExcel(String filePath, String sheetName, String header, List<String> titleList, List<List<Object>> contentList) throws IOException {
		File excel = null;
		if (contentList != null && contentList.size() > 0) {
			//Workbook wb = new HSSFWorkbook();
			Workbook wb = new XSSFWorkbook();
			//Workbook wb = new SXSSFWorkbook(1000);//larg file
			CreationHelper createHelper = wb.getCreationHelper();
			if (sheetName == null || "".equals(sheetName)) {
				sheetName = "sheet0";
			}
			// create a new sheet
			Sheet s = wb.createSheet(sheetName);

			Row r = null;// declare a row object reference
			Cell c = null;// declare a cell object reference

			//表头标题
			if (header != null && !"".equals(header)) {
				Row headerRow = s.createRow(0);
				headerRow.setHeight((short) 500);
				Cell hederCell = headerRow.createCell(0);
				s.addMergedRegion(new CellRangeAddress(0, 0, 0, titleList.size() - 1));//合并行
				hederCell.setCellValue(createHelper.createRichTextString(header));

				//设置样式
				CellStyle headerCellStyle = wb.createCellStyle();
				Font headerFont = wb.createFont();
				headerFont.setColor(new HSSFColor.BROWN().getIndex());
				headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
				headerCellStyle.setFont(headerFont);
				headerCellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
				headerCellStyle.setAlignment(CellStyle.ALIGN_CENTER);

				//headerCellStyle.setFillPattern(HSSFCellStyle.FINE_DOTS );
				headerCellStyle.setFillForegroundColor(new HSSFColor.BLUE().getIndex());
				headerCellStyle.setFillBackgroundColor(new HSSFColor.RED().getIndex());
				hederCell.setCellStyle(headerCellStyle);
			}

			if (titleList != null && titleList.size() > 0) {
				int rowNum = 0;
				if (header != null && !"".equals(header)) {
					rowNum = 1;
				}
				Row titleRow = s.createRow(rowNum);

				//设置样式
				CellStyle titleCellStyle = wb.createCellStyle();
				titleCellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
				titleCellStyle.setAlignment(CellStyle.ALIGN_CENTER);
				titleCellStyle.setLeftBorderColor(new HSSFColor.DARK_BLUE().getIndex());
				titleCellStyle.setFillBackgroundColor(new HSSFColor.BROWN().getIndex());

				for (int i = 0; i < titleList.size(); i++) {
					c = titleRow.createCell(i);
					c.setCellValue(createHelper.createRichTextString(titleList.get(i).toString()));

					c.setCellStyle(titleCellStyle);
				}

			}

			int rowStartWith = 2;
			if (header == null || "".equals(header)) {
				rowStartWith = 1;
			}

			if (contentList != null && contentList.size() > 0) {
				for (int i = 0; i < contentList.size(); i++) {
					r = s.createRow(i + rowStartWith);
					List rowList = contentList.get(i);
					for (int j = 0; j < rowList.size(); j++) {
						c = r.createCell(j);
						c.setCellValue(createHelper.createRichTextString(StrUtil.fixNull(rowList.get(j))));
					}
				}
			}

			// Save
			String filename = filePath;
			if (wb instanceof XSSFWorkbook) {
				filename = filename + "x";
			}

			FileOutputStream out = new FileOutputStream(filename);
			wb.write(out);
			out.close();
			wb.close();
			excel = new File(filename);
		} else {
			throw new IllegalArgumentException("ERROR:contentList can't not be empty!!");
		}
		return excel;
	}

	private static Object getCellInfo(Cell cell) {
		Object info = null;
		try {
			if (null != cell) {
				switch (cell.getCellType()) {
				case XSSFCell.CELL_TYPE_NUMERIC: // 数字   
					info = NumberToTextConverter.toText(cell.getNumericCellValue());
					break;
				case XSSFCell.CELL_TYPE_STRING: // 字符串   
					info = cell.getStringCellValue();
					break;
				case XSSFCell.CELL_TYPE_BOOLEAN: // Boolean   
					info = cell.getBooleanCellValue();
					break;
				case XSSFCell.CELL_TYPE_FORMULA: // 公式   
					info = cell.getCellFormula();
					break;
				case XSSFCell.CELL_TYPE_BLANK: // 空值   
					info = "";
					break;
				case XSSFCell.CELL_TYPE_ERROR: // 故障   
					info = "";
					break;
				default:
					break;
				}
			} else {
				info = "";
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return info;
	}

	public static void main(String[] args) throws Exception {
		File file = ResourceUtils.getFile("classpath:data.xlsx");
		List<Object[]> staffList = PoiUtil.readExcel(file, 0, 1);
	
		for (Object[] staff : staffList) {
			System.out.println("------");
			for (Object obj : staff) {
				System.out.println("" + obj);
			}
			System.out.println("------");
		}
	}
}
*/